import { useState } from "react";
import { Form } from "antd";

import { prompt } from "@/service";
import { updatePassword } from '../api'

export const useModifyPassword = () => {
  const [form] = Form.useForm();
  const [saving, setSaving] = useState(false);

  const submit = () => {
    setSaving(true)

    form.validateFields().then(values => {
      const { newPassword } = values;
      updatePassword(newPassword).then(() => {
        prompt.success("修改成功")
        setSaving(false)
      }).catch(() => setSaving(false))
    }).catch(() => setSaving(false))
  }

  return { saving, submit, form }
}
